package com.jp.knowledge.adapter.team_circle;


import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.TeamCircleModel;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.util.SpanUtils;

import java.util.List;

public class TeamCircleCommentsAdapter extends RecycleVAdapter<TeamCircleModel.CommentsBean> implements View.OnClickListener {

    private int parentPosition;

    public TeamCircleCommentsAdapter(Context context, @NonNull List<TeamCircleModel.CommentsBean> list, int position) {
        super(context, list);
        parentPosition = position;
    }

    public void setParentPosition(int position){
        this.parentPosition = position;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.team_circle_item_comments;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        TextView textView = (TextView) holder.getConvertView();
        textView.setTag(position);
        textView.setOnClickListener(this);

        TeamCircleModel.CommentsBean commentsBean = mList.get(position);

        SpanUtils spanUtils = new SpanUtils(mContext);
        if(commentsBean.getNickname() != null && !TextUtils.isEmpty(commentsBean.getNickname()))
        spanUtils.append(commentsBean.getNickname())
                .setForegroundColor(mContext.getResources().getColor(R.color.delete_text_click_color));
        if(commentsBean.getReply() != null
                && !TextUtils.isEmpty(commentsBean.getReply().getUid())
                && !TextUtils.isEmpty(commentsBean.getReply().getNickname())){
            spanUtils.append(mContext.getString(R.string.team_circle_reply))
                    .setForegroundColor(mContext.getResources().getColor(R.color.font_black_think));
            spanUtils.append(commentsBean.getReply().getNickname())
                    .setForegroundColor(mContext.getResources().getColor(R.color.delete_text_click_color));
        }
        spanUtils.append(":"+commentsBean.getContent())
                .setForegroundColor(mContext.getResources().getColor(R.color.font_black_think));
        textView.setText(spanUtils.create());
    }

    @Override
    public void onClick(View v) {
        if(commentClickListener != null){
            commentClickListener.onCommentClick(parentPosition, (int)v.getTag());
        }
    }

    private OnCommentClickListener commentClickListener;
    public void setCommentClickListener(OnCommentClickListener commentClickListener){
        this.commentClickListener = commentClickListener;
    }
    public interface OnCommentClickListener{
        void onCommentClick(int parentPosition, int position);
    }
}
